[iPhone] How to order an array

Posted by Fabrizio on Stack Overflow See other posts from Stack Overflow or by Fabrizio
Published on 2010-05-12T14:40:22Z Indexed on 2010/05/12 14:44 UTC
Read the original article Hit count: 267

Hi all, I got an array in my app and I need to order by one of its key.

Basically what the app does is taking latitude and longitude somewhere, calculate the distance from my actual position and create an array containing a key called "distance".

I'm using

myArray sortUsingDescriptors: [NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"distance" ascending:YES] autorelease]]];

I'm not sure it's working, I mean the first results are ordered but then it shows distance closer to the previous, as example:

0.8 km 1.6 km 1.9 km 10053.9 km 1098.0 km 2372.0 km 470.5 km

Any suggestion?

I thank you in advance for any kind of help.

Fabrizio

© Stack Overflow or respective owner

Related posts about iphone-sdk-3.0

Related posts about nsarray